/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FileChooser.java
 *
 * Created on 30.Mar.2009, 10:45:43
 */

package com.meraklisina.latexeditor;

import java.awt.Component;
import java.io.*;

/**
 *
 * @author kursattopcu
 */
public class FileChooser extends javax.swing.JPanel {

    /** Creates new form FileChooser */
    public FileChooser() {
        initComponents();
        //fileChooser.showOpenDialog(null);
    }

    public File GetSelectedFile()
    {
        return fileChooser.getSelectedFile();
    }

    public void ShowChooseDialog(Component parent){
        SetFileFilter();
        this.fileChooser.showOpenDialog(parent);
    }

    public void ShowSaveDialog(Component parent){
        SetFileFilter();
        this.fileChooser.showSaveDialog(parent);
    }

    public void SetFileFilter(){
        this.fileChooser.setFileFilter(new javax.swing.filechooser.FileFilter() {
	        public boolean accept(File f) {
	          String name = f.getName().toLowerCase();

	          return name.endsWith(".tex") || f.isDirectory();
	        }

	        public String getDescription() {
	          return "Latex files";
	        }
	      });
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        fileChooser = new javax.swing.JFileChooser();

        fileChooser.setCurrentDirectory(new java.io.File("C:\\Documents and Settings\\kursattopcu\\Desktop"));
        fileChooser.setName("fileChooser"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(fileChooser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(fileChooser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JFileChooser fileChooser;
    // End of variables declaration//GEN-END:variables

}
